home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************/
- /* */
- /* CliZap.rexx: Copyright © 1991-92, Dineen Edwards Group, Inc. */
- /* All rights reserved. */
- /* */
- /* program to enter relative offsets, verify data, and replacement */
- /* data, for the purpose of zapping an object file to fix bugs. The */
- /* data can be entered as a file or from the cli. */
- /* */
- /* When a list of blank delimited file names are specified, the */
- /* files are used as input for the zap application. When no */
- /* parameters are specified, the data is to be entered from the CLI.*/
- /* The data from the CLI or from the file is in the following */
- /* format: */
- /* */
- /* File Name: - name of file to zap. */
- /* */
- /* Offset: - offset from start of file for zap. */
- /* specified as newzap decimal sector and */
- /* and hexidecimal cursor, or as decimal */
- /* relative offset. */
- /* Verify Data: - Hexidecimal data at the location to be */
- /* zapped. */
- /* Replace Data: - Hexidecimal data to be placed at location*/
- /* offset. */
- /* * the Offset, Verify, and Replace data */
- /* prompts are read until a null line is */
- /* read. Once read, the next two prompts */
- /* are given. */
- /* */
- /* Check Sum: - Hexidecimal check sum used to verify */
- /* accuracy of data entered. */
- /* Apply Zap: - Yes to apply zap. No to skip application.*/
- /* */
- /*************************************************************************/
-
- /*************************************************************************/
- /*************************************************************************/
- /** **/
- /** * * * Warning * * * **/
- /** **/
- /** This program was written to modify object libraries. Modifying **/
- /** modifying object libraries can have catastrophic results. **/
- /** **/
- /** * * * USE AT YOUR OWN RISK * * * **/
- /** **/
- /** **/
- /*************************************************************************/
- /*************************************************************************/
-
- numeric digits 14
- say "CliZap.rexx: Copyright © 1991-92, Dineen Edwards Group, Inc.,"
- say " All rights reserved." 'a'x
-
- parse arg files /* get the list of zap files */
- min = 18 /* set minimum prompt length */
-
- if files = '' then files = '*' /* if no file list, set file to CLI */
- error2 = 0 /* set error level */
-
- do while files ~= '' /* loop through list of files */
- parse var files inpt files /* find first file and leave rest */
- call close(STDIN) /* close STDIN file handle */
- if ~open(STDIN,inpt,'r') /* reopen STDIN for first file */
- then do /* on error, give error and exit */
- say "Input file '"inpt"' not found."
- exit 20
- end
-
- file = GetLine('Enter file name:') /* get the file name */
-
- /* display status of zap */
- say
- say "Processing zaps from '"inpt"'"
- say "Zapping file '"file"'"
-
- chksum = 0 /* set default check sum to zero */
- error = 0 /* set errors off */
- applied = 0 /* set applied off */
- zap = 0 /* set zap count for array to zero */
- off. = "" /* set compounds to null */
- data. = "" /* set compounds to null */
-
- if ~open('f',file,'A') /* open file to be zapped */
- then do
- say "Can't open '"file"'." /* on error, say it */
- exit 10 /* exit on error */
- end
-
- do forever /* loop until null response */
- ioerr = 0 /* set i/o error flag off */
- a = GetLine('Offset:') /* get verify data */
- parse var a o p . /* get the offset */
- o = translate(o,' ',',') /* make commas, spaces */
- if o = '' then leave /* null leave forever loop */
- if ~datatype(o,'n')
- then do
- say 'Offset' d 'not specified as a decimal'
- error = 1
- end
-
-
- if p~='' /* newzap format? */
- then do
- if ~datatype(p,'x') /* check validity of position */
- then do
- say 'Cursor position' p 'not specified in hexadecimal'
- error = 1
- end
- else o = (o-1)*512+x2d(p) /* calculate decimal offset */
- end
-
- if inpt ~= '*' | ~error /* only if not error */
- then do
- a = GetLine('Verify Data:') /* get verify data */
- parse var a v comm /* separate it */
- v = translate(v,' ',',') /* make commas, spaces */
- if v = '' then leave /* null leave forever loop */
- if datatype(v,'x')
- then v = x2c(v) /* make character string */
- else do
- say 'Verify Data is not valid hexadecimal'
- error = 1
- end
- end
-
- if inpt ~= '*' | ~error /* only if not error */
- then do
- a = GetLine('Replace Data:') /* get replacement data */
- parse var a r comm /* separate it */
- r = translate(r,' ',',') /* make commas, spaces */
- if r = '' then leave /* null leave forever loop */
- if datatype(r,'x')
- then r = x2c(r) /* make character string */
- else do
- say 'Replace Data is not valid hexadecimal'
- error = 1
- end
- end
-
- if seek('f',o,'B') = -1 /* seek to the offset */
- then do
- error = 1
- say 'Offset' o 'outside of file being zapped'
- end
- else if inpt ~= '*' | ~error
- then do
- old = readch('f',length(r)) /* find old data */
-
- if left(old,length(v)) ~== v /* varify and old data the same? */
- then if (left(old,length(r))) ~== r /* replacement data same? */
- then do
- error = 1 /* no, set error flag */
- say "Old data '"c2x(old)"' not equal Verify data '"c2x(v)"' at offset" o'.'
- end
- else applied = 1 /* set applied flag */
- end
-
- if inpt = '*' & error /* if from console, and error */
- then do
- error = 0 /* allow continuation after error */
- say '0a'x "Re-enter zap data" /* tell user what is happening */
- end
- else do
- /* save data and calculate check sum */
- off.zap = o /* save the offset in array */
- data.zap = r /* save replace data in array */
- ver.zap = v /* save the verify */
- old.zap = old /* save old data in array */
-
- /* loop through replacement data for check sum */
- do i = 1 to length(r)
- chksum = chksum + c2d(substr(r,i,1))
- end
- chksum = chksum + o /* add offset for check sum */
- zap = zap + 1 /* increment zap array pointer */
- end
- end
-
- if zap = 0 /* any, zap data? */
- then do
- say 'No valid zap data entered' /* tell user what happened */
- exit 5 /* set the return code */
- end
-
- /* ask for check sum data */
- a = GetLine("Enter Check Sum:") /* get check sum */
- parse var a a comm /* separate the data */
- a = translate(a,' ',',') /* make commas, spaces */
- a = x2d(a) /* make it a decimal value */
- if a ~= chksum /* check for equality */
- then do
- /* give error, when not equal */
- say "Calculated check sum '"d2x(chksum)"' not equal '"d2x(a)"'."
- error = 1 /* set error flag */
- end
-
- if error /* if error found */
- then say 'Prior error disabled zap' /* display error */
- else do /* otherwise... */
- if zap > 0 /* any zap info entered? */
- then do /* check cor application */
- /* set apply prompt */
- a = GetLine("Apply the zap?") /* get answer */
- a = word(a,1) /* get the first word */
- if abbrev("YES",a,1) ~= 0 || abbrev("APPLY",a,1) ~= 0 /* yes, apply it */
- then do
- if applied
- then say 'Zap already applied'
- else do i = 0 to zap-1
- call seek('f',off.i,'B') /* seek to offset */
- call writech('f',data.i) /* write the data */
- /* list the update */
- say "Offset: "off.i" Old Data: "c2x(old.i)" New Data: "c2x(data.i)
- end
- end
- else if abbrev("REMOVE",a,1)
- then do i = 0 to zap-1
- call seek('f',off.i,'B') /* seek to offset */
- call writech('f',ver.i) /* write the data */
- /* list the update */
- say "Offset: "off.i" Old Data: "c2x(old.i)" New Data: "c2x(ver.i)
- end
- else do
- say '0a'x 'Zap not applied'
- do i = 0 to zap-1 /* list it */
- say "Offset: "off.i" Current Data: "c2x(old.i)" Replace Data: "c2x(data.i)
- end
- end
- end
- end
- call close('f') /* close the file */
- error2 = error | error2 /* set second error level */
- end
-
- if error2 then exit 10 /* give bad return code */
- exit
-
- GetLine:
- parse arg a
- options prompt left(a,min) /* set prompt */
- a = '*'
- do while left(a,1) = '*'
- parse upper pull a /* get the line */
- a = translate(a,' ',' ') /* make commas, spaces */
- end
- return a
-